﻿using MediatR;
using Microsoft.Extensions.Hosting;
namespace NM.Module.Manager.API.EventHandlers;

public class InstallEventHandler : INotificationHandler<InstallEvent>
{
    private readonly IHostApplicationLifetime _appLifetime;

    public InstallEventHandler(IHostApplicationLifetime appLifetime)
    {
        _appLifetime = appLifetime;
    }

    public Task Handle(InstallEvent notification, CancellationToken cancellationToken)
    {
        if (notification.RestartAfterInstall)
        {         
            _appLifetime.StopApplication();
            return Task.CompletedTask;
        }
        return Task.CompletedTask;
    }
}